import 'dart:io';

import 'package:flutter/material.dart';

const double DETAIL_BOTTOM_BAR_HEIGHT = 54.0;
const Color iconDefaultColor = Color(0xFF222222); //FDColors.G3;
const Color iconDefaultColorNew = Color(0xFFBFBFBF);

class BottomBar extends StatefulWidget {
  const BottomBar({Key? key}) : super(key: key);

  @override
  State<BottomBar> createState() => _BottomBarState();
}

class _BottomBarState extends State<BottomBar> {
  @override
  Widget build(BuildContext context) {
    return FDBottomBar(
        child: Container(
          width: MediaQuery.of(context).size.width,
          height: DETAIL_BOTTOM_BAR_HEIGHT,
          padding: const EdgeInsets.only(
              left:  16.0,
              right: 16.0),
          child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                getLeftWidgets(),
                Expanded(child: Container()),
                getRightWidgets(),
              ]),
        ));
  }

  Widget getLeftWidgets() {
    return Row(
      children: [
        Container(
          padding: const EdgeInsets.only(right: 16),
          height: 40,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Image.asset(
                'assets/images/make_price.png',
                width: 24,
                height: 24,
              ), const Text(
                '出价',
                style: TextStyle(
                  color: Color(0xFFA3A3A3),
                  fontSize: 10,
                ),
              ),
            ],
          ),
        ),
        Container(
          padding: const EdgeInsets.only(right: 16),
          height: 40,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Image.asset(
                'assets/images/chat.png',
                width: 24,
                height: 24,
              ), const Text(
                '20',
                style: TextStyle(
                  color: Color(0xFFA3A3A3),
                  fontSize: 10,
                ),
              ),
            ],
          ),
        ),
        SizedBox(
          height: 40,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Image.asset(
                'assets/images/collection.png',
                width: 24,
                height: 24,
              ), const Text(
                '190',
                style: TextStyle(
                  color: Color(0xFFA3A3A3),
                  fontSize: 10,
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  Widget getRightWidgets() {
    return Container(
      padding: const EdgeInsets.fromLTRB(12, 6, 12, 6),
      decoration: const BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(20)),
        color: Color(0xFFFFE60F),
      ),
      child: Text(
        '我想要',
          style: TextStyle(
            fontSize: 16.0,
            color: const Color(0xFF333333),
            height: (Platform.isAndroid) ?  1.2 : 1.0,
            fontWeight: (Platform.isAndroid) ? FontWeight.bold : FontWeight.w500,
          ),
      ),
    );

  }
}



class FDBottomBar extends StatelessWidget {
  const FDBottomBar(
      {Key? key,
        required this.child,
        this.margin,
        this.opacity,
        this.backgroundColor = Colors.white,
        this.border,
        this.borderRadius,
        this.padding,
        this.onClick})
      : super(key: key);

  final Widget child;

  /// margin
  final EdgeInsetsGeometry? margin;

  final double? opacity;

  /// background  color
  final Color backgroundColor;

  /// border for all
  final BoxBorder? border;

  /// Radius for all
  final BorderRadiusGeometry? borderRadius;

  /// padding
  final EdgeInsetsGeometry? padding;

  /// oncClick
  final VoidCallback? onClick;

  @override
  Widget build(BuildContext context) {
    final Widget target = SafeArea(
      bottom: true,
      left: false,
      right: false,
      top: false,
      child: child,
    );
    if (margin == null &&
        opacity == null &&
        backgroundColor == null &&
        border == null &&
        padding == null &&
        onClick == null &&
        borderRadius == null) {
      return target;
    } else {
      return FDContainer(
        margin: margin,
        opacity: opacity,
        backgroundColor: backgroundColor,
        border: border,
        borderRadius: borderRadius,
        padding: padding,
        onClick: onClick,
        child: target,
      );
    }
  }
}

class FDContainer extends StatefulWidget {
  const FDContainer({
    Key? key,
    required this.child,
    this.width,
    this.height,
    this.opacity,
    // color
    required this.backgroundColor,
    // border
    this.border,
    // radius
    this.borderRadius,
    // margin
    this.margin,
    // padding
    this.padding,
    this.alignment,
    // click
    this.onClick,
  }) : super(key: key);

  final Widget child;

  final double? width;

  final double? height;

  final double? opacity;

  /// background  color
  final Color? backgroundColor;

  final Alignment? alignment;

  /// border for all
  final BoxBorder? border;

  /// Radius for all
  final BorderRadiusGeometry? borderRadius;

  /// margin
  final EdgeInsetsGeometry? margin;

  /// padding
  final EdgeInsetsGeometry? padding;

  /// oncClick
  final VoidCallback? onClick;

  @override
  State<StatefulWidget> createState() {
    return _FDContainerState();
  }
}

class _FDContainerState extends State<FDContainer> {
  @override
  Widget build(BuildContext context) {
    Widget target = widget.child;
    if (widget.margin != null ||
        widget.padding != null ||
        widget.backgroundColor != null ||
        widget.border != null ||
        widget.borderRadius != null) {
      target = Container(
          width: widget.width,
          height: widget.height,
          margin: widget.margin,
          alignment: widget.alignment,
          padding: widget.padding,
          decoration: BoxDecoration(
              color: widget.backgroundColor,
              border: widget.border,
              borderRadius: widget.borderRadius),
          child: widget.child);
    }

    if (widget.opacity != null) {
      target = Opacity(opacity: widget.opacity!, child: target);
    }

    if (widget.onClick != null) {
      target = GestureDetector(onTap: widget.onClick, child: target);
    }

    return target;
  }
}

